// pages/components/good_recommend.js
const api = require("../../request/api")
const request = require("../../request/request")
const util = require("../../utils/util")
const App = getApp();
// const computedBehavior = require("miniprogram-computed").behavior;
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        more_list: Array,
        if_show_cart: {
            type: Boolean,
            value: true
        },

    },
    // behaviors: [computedBehavior],
    /**
     * 组件的初始数据
     */
    data: {
        day: '',
        hour: "",
        minute: "",
        second: "",
    },
    computed: {

    },

    /**
     * 组件的方法列表
     */
    methods: {
        countTime() {
            //获取当前时间
            var date = new Date();
            var now = date.getTime();
            //设置截⽌时间
            var str = "2022/7/1 00:00:00";
            var endDate = new Date(str);
            var end = endDate.getTime();
            //时间差
            var leftTime = end - now;
            //定义变量 d,h,m,s保存倒计时的时间
            var d, h, m, s;
            if (leftTime >= 0) {
                d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
                h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
                m = Math.floor(leftTime / 1000 / 60 % 60);
                s = Math.floor(leftTime / 1000 % 60);
            }
            else {
                return
            }
            // 将倒计时赋值到div中
            this.setData({
                day: d + '天',
                hour: h + "时",
                minute: m + "分",
                second: s + "秒",
            })
            setTimeout(() => this.countTime(), 1000);
        },
        go_detail(e) {
            this.triggerEvent("go_detail", e)
        },
        cart_add() {
            this.triggerEvent("cart_add")
        },
    },
})
